package com.framework.demo.action;

import com.framework.base.action.BaseAction;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LIN
 * @date 2021-05-08
 */
public class DemoAction extends BaseAction {

    private Object data;

    public void setJson(Object data) {
        this.data = data;
    }

    public Object getJson() {
        return data;
    }

    public DemoAction(){
        System.out.println(this.getClass().getName());
    }

    @PostConstruct
    public void init(){
        System.out.println(this.getClass().getName()+":初始化");
    }

    @Override
    public String execute() throws Exception {
        String ret = "success";
        Map<String, String[]> parameterMap = this.getRequest().getParameterMap();
        String[] submitFlags = parameterMap.get("submitFlag");
        String submitFlag = submitFlags[0];
        if("index".equals(submitFlag)){
            return "index";
        }else {
            Map<String ,String> map = new HashMap<>(16);
            map.put("a","1");
            map.put("b","2");
            setJson(map);
            return "success";
        }
    }
}
